package com.mx.kn.cstf2.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

import kn.cstf2.assign.Bean.ListaTablaBean;
import kn.cstf2.assign.Server.AssignServer;
import kn.cstf2.global.Utils.CstF2Exception;
import kn.cstf2.transition.Bean.TransitionBean;
import kn.mx.cstf2.sql.AssignSql;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import com.mx.kn.cstf2.dao.AssignDao;
import com.mx.kn.cstf2.dto.ForoDto;


@Repository
@Component("assignDao")
public class AssignDaoImpl implements AssignDao{
	

	private JdbcTemplate jdbcStksf2;
	private JdbcTemplate jdbcCustomerSalesToolKit;

	@Autowired
	public void setDataSourceStkfsf2(@Qualifier("dataSourceStkfsf2") DataSource DataSourceStkfsf2) {
		this.jdbcStksf2 = new JdbcTemplate(DataSourceStkfsf2);
	}
	
	@Autowired
	public void setDataSourceCustomerSalesToolKit(@Qualifier("dataSourceCustomerSalesToolKit")
			DataSource dataSourceCustomerSalesToolKit) {
		this.jdbcCustomerSalesToolKit = new JdbcTemplate(dataSourceCustomerSalesToolKit);
		
	}

	
	public ArrayList<ListaTablaBean> obtenerListaTabla(Integer iduser) {
		 try{
							List<ListaTablaBean> lst = jdbcStksf2.query(
						 AssignSql.SELECCIONAR_KNKEYS,new Object[] {iduser} ,new BeanPropertyRowMapper(ListaTablaBean.class));
				
				for(ListaTablaBean tabla : lst){
					 for (Map datoLista : jdbcCustomerSalesToolKit.queryForList(AssignSql.SELECCIONAR_COMPANY_FROMSTK,new Object[] {tabla.getKnkey()})) {
						  tabla.setCompanyname((String)datoLista.get("companyname"));
		                  tabla.setCreation((String)datoLista.get("creationdate"));
					  }
				}
		 return (ArrayList<ListaTablaBean>) lst;	

		 }catch (Exception ex) {
	         
	            throw new CstF2Exception("Error al obtener el Usuario desde la base de datos");
	     }
		 
		 

			

		 
		
	}



	

}
